package spotGUI.supportGUI;

import java.awt.Component;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.border.EmptyBorder;

import managers.SupportManager;
import managers.messengerManager.FeedbackManager;
import managers.messengerManager.MessengerManager;
import utils.StackTracePrinter;
import java.util.ResourceBundle;

public class CommentPanel extends JPanel {
	private JLabel title;
	private JTextArea textArea;
	private JScrollPane scrollPane;
	private JButton btnSend;
	private JLabel lblSent;
	public CommentPanel() {
		setBorder(new EmptyBorder(10, 10, 0, 10));
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[]{450, 17, 0};
		gridBagLayout.rowHeights = new int[]{29, 100, 2, 0};
		gridBagLayout.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE};
		gridBagLayout.rowWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE};
		setLayout(gridBagLayout);
		
		title = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("CommentPanel.title.text")); //$NON-NLS-1$ //$NON-NLS-2$
		title.setAlignmentX(Component.CENTER_ALIGNMENT);
		GridBagConstraints gbc_title = new GridBagConstraints();
		gbc_title.gridwidth = 2;
		gbc_title.fill = GridBagConstraints.BOTH;
		gbc_title.insets = new Insets(0, 0, 5, 0);
		gbc_title.gridx = 0;
		gbc_title.gridy = 0;
		add(title, gbc_title);
		
		scrollPane = new JScrollPane();
		GridBagConstraints gbc_scrollPane = new GridBagConstraints();
		gbc_scrollPane.gridwidth = 2;
		gbc_scrollPane.fill = GridBagConstraints.BOTH;
		gbc_scrollPane.insets = new Insets(0, 0, 5, 0);
		gbc_scrollPane.gridx = 0;
		gbc_scrollPane.gridy = 1;
		add(scrollPane, gbc_scrollPane);
		
		textArea = new JTextArea();
		textArea.setOpaque(false);
		scrollPane.setViewportView(textArea);
		textArea.setWrapStyleWord(true);
		textArea.setLineWrap(true);
		
		btnSend = new JButton(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("CommentPanel.btnSend.text")); //$NON-NLS-1$ //$NON-NLS-2$
		btnSend.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				lblSent.setVisible(true);
				try {
					SupportManager.getSharedInstance().sendComment(textArea.getText());
				} catch (Exception e) {
					StackTracePrinter.print(e);
					MessengerManager.getSharedInstance().getFeedbackManager().updateStatus(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("CommentPanel.error"), FeedbackManager.WARNING);
				}
			}
		});
		
		lblSent = new JLabel(ResourceBundle.getBundle("spotGUI.supportGUI.messages").getString("CommentPanel.lblSent.text")); //$NON-NLS-1$ //$NON-NLS-2$
		lblSent.setVisible(false);
		GridBagConstraints gbc_lblSent = new GridBagConstraints();
		gbc_lblSent.fill = GridBagConstraints.BOTH;
		gbc_lblSent.insets = new Insets(0, 0, 0, 5);
		gbc_lblSent.gridx = 0;
		gbc_lblSent.gridy = 2;
		add(lblSent, gbc_lblSent);
		btnSend.setAlignmentX(1.0f);
		GridBagConstraints gbc_btnSend = new GridBagConstraints();
		gbc_btnSend.anchor = GridBagConstraints.SOUTHEAST;
		gbc_btnSend.gridx = 1;
		gbc_btnSend.gridy = 2;
		add(btnSend, gbc_btnSend);
	}

}
